# -*- coding: utf-8 -*-
#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app


from base import *
from weather.model import *

class MainPage(BaseRequestHandler):
    def get(self):
        self.render('template/weather/admin.html')
        
class AddCity(BaseRequestHandler):
    def get(self):
        list = City.all()
        self.render('template/weather/admin_city.html',{'list':list})
        
    def post(self):
        name = self.request.get('name') 
        url = self.request.get('url') 
        remark = self.request.get('remark')  
        if name and url:
            city = City()
            city.name = name
            city.url = url
            city.remark = remark
            city.put()
            self.redirect('/console/add_city')
            
class DelCity(BaseRequestHandler):
    
    def post(self):
        keys = self.request.get_all('list')
        for k in keys:
            City.get(k).delete()
        self.redirect('/console/add_city')
        
application = webapp.WSGIApplication(
                                     [('/console/', MainPage),
                                      ('/console/add_city', AddCity),
                                      ('/console/deletecity',DelCity),                                  
                                      ],debug=True)


def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()